﻿using UnityEngine;
using System.Collections;
using Dict.Config;
using Dict.Blo;
using Dict.DataModel;

namespace UI
{
    public class SkillItem : MonoBehaviour
    {
        public UILabel skillName;
        public UILabel skillType;
        public UILabel skillLevel;
        public UILabel propName;        //普通技能为：“获得能量”，必杀技为：“冷却时间”
        public UILabel propValue;       //普通技能为：“获得能量”，必杀技为：“冷却时间”
        public GameObject skillLevelRoot;
        public TextureKit skillIcon;
        public UILabel skillDesc;
        public UISprite whiteBlock;
        public int fixedHeight;
        public int minHeight;

        public UISprite propIcon;
        public UILabel propType;
        public int SkillItemHeight
        {
            get
            {
                return whiteBlock.height;
            }
        }

        protected void ResetSkillHeight()
        {
            int height = skillDesc.height + fixedHeight;

            //int width = whiteBlock.width;
            if( height<minHeight )
            {
                whiteBlock.height = minHeight;
            }
            else
            {
                whiteBlock.height = height;
            }
        }

        void SetSkillType(int type)
        {
            switch (type)
            {
                case 1:
                    propIcon.spriteName = "UI_item_01";
                    propType.text = TableTextBlo.GetText("skill_type_physics");
                    break;
                case 2:
                    propIcon.spriteName = "UI_item_02a";
                    propType.text = TableTextBlo.GetText("skill_type_magic");
                    break;
                case 3:
                    propIcon.spriteName = "UI_item_02";
                    propType.text = TableTextBlo.GetText("skill_type_cure");
                    break;
                default:
                    Debug.LogError("Type error: " + type);
                    break;
            }   
        }

        public virtual void SetSkill(UISkill skill,int index, int breakLevel)
        {
            skillIcon.textureName = skill.skillData.SkillIcon;
            SetSkillType(DictSkillCastBlo.GetSkillExportType(skill.skillData.SkillId));
            skillName.text = TableTextBlo.GetText("name_skill_" + skill.skillData.SkillId);
            
            if(skill.skillIndex < 2)
            {
                skillLevelRoot.SetActive(false);
                propName.text = TableTextBlo.GetText("got_power");
                string str = string.Format("{0}", (int)Dict.Blo.DictSkillCastBlo.GetSkillAddAnger(skill.skillData.SkillId));
                propValue.text = str;

                skillDesc.text = TableTextBlo.GetText("desc_skill_" + skill.skillData.SkillId);
                skillType.text = TableTextBlo.GetText(string.Format("normal_skill_{0:d}", index + 1));
            }
            else
            {
                skillLevelRoot.SetActive(true);
                skillLevel.text = TableTextBlo.GetText("level") + breakLevel.ToString();
                skillType.text = "[" + TableTextBlo.GetText("unique_skill") + "]";

                int value = skill.skillData.LevelGrowFactor * (breakLevel - 1) + (int)DictSkillCastBlo.GetSkillExportFactor(skill.skillData.SkillId);
                string descstr = string.Format(TableTextBlo.GetText("desc_skill_" + skill.skillData.SkillId), value);
                skillDesc.text = descstr;

                propName.text = TableTextBlo.GetText("cooldown_time");
                propValue.text = Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.SkillCoolDown.ToString() + TableTextBlo.GetText("round");
            }
        }
    }
}
